

package controller;

import dal.userDal;
import entity.User;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

@ManagedBean
@SessionScoped
public class UserController {
    private List<User> users;
    private userDal userDal;
    private User currentUser;

    public UserController() {
        userDal = new userDal();
    }

    private void init(){
        users = userDal.loadUser();
    }

    public List<User> getUsers() {
        init();
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public User getCurrentUser(){
        return currentUser;
    }

    public void setCurrentUser(User currentUser){
        this.currentUser = currentUser;
    }

    public String Login(){
        currentUser = new User();
        return "login";
    }

    public String doLogin(){
        List<User> list = userDal.loadUser();
        list.add(currentUser);
        userDal.saveUsers(list);
        return "show";
    }
}
